package com.longtengyuyun.dcl;

import java.util.Objects;

/**
 * @author ZhaoYunLong
 * @date 2022/4/14
 * @description
 */
public class ClassDemo {


//    private volatile ClassDemo instance;
//
//    public ClassDemo getInstance(){
//        if (Objects.isNull(instance)) {
//            synchronized (this) {
//                if (Objects.isNull(instance)) {
//                    return new ClassDemo();
//                }
//            }
//        }
//        return instance;
//    }

    private static volatile ClassDemo instance;

    public static ClassDemo getInstance(){
        if (Objects.isNull(instance)) {
            synchronized (ClassDemo.class) {
                if (Objects.isNull(instance)) {
                    return new ClassDemo();
                }
            }
        }
        return instance;
    }
}
